<?php
class App_Module_Admin_Component_Uploads_Ctrl_Std_Cli extends Mozg_Controller_Instance
{
	protected $_filesDeleteAtTime = 50;

    /**
		экшен по-умолчанию
	*/
    public function PrAction ()
    {
        $this->clearPr();
    }

    public function clearPrAction()
    {
    	$paginator = new Mozg_Paginator(1, $this->_filesDeleteAtTime);
		$files = Mozg_Mapper::Get('Uploads')->GetList(array('toDate' => time() - 3600 * 24), $paginator);

		$paths = array();
		foreach ($files as $file)
		{
			$paths[] = $file->GetPath();
			if ($file->GetPath() && file_exists(_ROOT_PATH.$file->GetPath()))
			{
				@unlink(_ROOT_PATH.$file->GetPath());
			}
		}

		$filesDeleted = 0;
		if (sizeof($paths))
		{
			$filesDeleted = Mozg_Mapper::Get('Uploads')->Delete(array(
								'paths' => $paths
							));
		}

    	Mozg::Response('std')->SetBody('Files deleted: ' .$filesDeleted);
    }
}